package HbaseConnect;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.ZooKeeperConnectionException;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.HTable;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class HbaseDemo {
	String Name="hi";
	HBaseAdmin admin;
	HTable htable;
	
	@Before
	public void before() throws Exception, ZooKeeperConnectionException, IOException{
		Configuration conf = new Configuration();
		
		//完全分布式
		conf.set("hbase.zookeeper.quorum", "node2,node4,node3");
		admin = new HBaseAdmin(conf);
		htable = new HTable(conf, Name);
	}
	
	@After
	public void end() throws Exception{
		if(admin!=null){
			admin.close();
		}
		if(htable!=null){
			htable.close();
		}
	}
	
	
	@Test
	public void createTable() throws Exception {
		if(admin.tableExists(Name)) {
			admin.disableTable(Name);
			admin.deleteTable(Name);
		}
		
		HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(Name));
		
		HColumnDescriptor cf = new HColumnDescriptor("cf".getBytes());
		cf.setInMemory(true);
		cf.setMaxVersions(1);
		
		desc.addFamily(cf);
		
		admin.createTable(desc);
	}
	
	@Test
	public void deleteTable(){
		
	}
	
	@Test
	public void change(){
		
	}
	
	
	
}
